﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VgoCardChange.Models;
using VgoCardChange.Models.Objects;

namespace VgoCardChange.Controllers
{
    public class CateController : Controller
    {
        //
        // GET: /Cate/

        public ActionResult Index()
        {
            return View();
        }
        public ActionResult GetCates()
        {
            CateModels CatMd = new CateModels();
            List<Cate> listcate = new List<Cate>();
            listcate = CatMd.GetCates();
            ViewData["listcate"] = listcate;
            return View();
        }
        public ActionResult CreateCate()
        {
            return View();
        }
        [HttpPost]
        public ActionResult CreateCate(string CateName, string Descripton)
        {
            CateModels CatMd = new CateModels();
            Cate cate = new Cate();
            cate.CateName = CateName;
            cate.Description = Descripton;
            CatMd.CreateCate(cate);
            return RedirectToAction("GetCates");
        }
        public ActionResult EditCate(int CateID)
        {
            CateModels CatMd = new CateModels();
            List<Cate> listcateid = new List<Cate>();
            listcateid = CatMd.GetCateID(CateID);
            ViewData["listcateid"] = listcateid;
            return View(listcateid);
        }
        [HttpPost]
        public ActionResult EditCate(int CateID, string CateName, string Description)
        {
            CateModels CatMd = new CateModels();
            Cate cate = new Cate();
            cate.CateID=CateID;
            cate.CateName=CateName;
            cate.Description=Description;
            CatMd.EditCate(cate);
            return RedirectToAction("GetCates");
        }
        public ActionResult DeleteCate(int CateID)
        {
            CateModels CatMd = new CateModels();
            List<Cate> listcateid = new List<Cate>();
            listcateid = CatMd.GetCateID(CateID);
            ViewData["listcateid"] = listcateid;
            return View(listcateid);
 
        }
        [HttpPost]
        public ActionResult DeleteCate(int CateID, FormCollection coll)
        {
            CateModels CatMd = new CateModels();
            CatMd.DeleteCate(CateID);
            return RedirectToAction("GetCates");
        }

    }
}
